using Common.Commands.LeadCommands;
using Common.Views;
using Core.Domain.Model;
using NUnit.Framework;
using Sanelib.Common.Helpers;
using Sanelib.DataView;

namespace IntegrationTests.Processors
{
    public class LeadsProcessorTester : IntegrationTestBase
    {
        [Test]
        public void ShouldAddLeads()
        {
            var command = new AddLead
            {
                Id = GuidComb.New(),
                Name = "Nikunj",
                CompanyName = "Sanelib",
                Email = "nikunjbbalar@gmail.com",
                Phone = "(+91) 9099-791517",
                Description = "Connect for bussiness"
            };
            ProcessCommand(command);
            var repo = GetInstance<IViewRepository<LeadView>>();
            var leadsView = repo.GetById(command.Id);

            Assert.AreEqual(command.CompanyName, leadsView.CompanyName);
        }

        [Test]
        public void ShouldAddAnonymousLead()
        {
            var command = new AddAnonymousLead
            {
                Id = GuidComb.New(),
                Name = "Nikunj",
                CompanyName = "Sanelib",
                Email = "nikunjbbalar@gmail.com",
                Phone = "(+91) 9099-791517",
                Description = "Connect for bussiness"
            };
            ProcessCommand(command);
            var repo = GetInstance<IViewRepository<LeadView>>();
            var leadsView = repo.GetById(command.Id);

            Assert.AreEqual(command.CompanyName, leadsView.CompanyName);
        }

        [Test]
        public void ShouldDeleteLeads()
        {
            var leads = new Lead
            {
                Id = GuidComb.New(),
                Name = "Nikunj",
                CompanyName = "Sanelib",
                Email = "nikunjbbalar@gmail.com",
                Phone = "(+91) 9099-791517",
                Description = "Connect for bussiness"
            };
            Persist(leads);

            var command = new DeleteLead(leads.Id);
            ProcessCommand(command);

            var repo = GetInstance<IViewRepository<LeadView>>();
            var leadsView = repo.GetById(command.Id);

            Assert.IsNull(leadsView);
        }

        [Test]
        public void ShouldUpdateLeads()
        {
            var leads = new Lead
            {
                Id = GuidComb.New(),
                Name = "Nikunj",
                CompanyName = "Sanelib",
                Email = "nikunjbbalar@gmail.com",
                Phone = "(+91) 9099-791517",
                Description = "Connect for bussiness"
            };
            Persist(leads);

            var command = new UpdateLead
            {
                Id = leads.Id,
                Name = "Sunnny",
                CompanyName = "Sanelib",
                Email = "sunny@gmail.com",
                Phone = "(+91) 9374-021723",
                Description = ""
            };
            ProcessCommand(command);

            var repo = GetInstance<IViewRepository<LeadView>>();
            var leadsView = repo.GetById(command.Id);

            Assert.AreEqual(leadsView.Id, leads.Id);
            Assert.AreNotEqual(leads.Email, leadsView.Email);
        }
    }
}